package com.dingding.special.common.facade.impl;

import javax.annotation.Resource;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dto.FacadeResult;
import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.facade.special.ISpecialFacade;
import com.dingding.facade.special.trasfer.calc_price.ReqCalculationAmountDTO;
import com.dingding.facade.special.trasfer.calc_price.ResCalculationAmountDTO;
import com.dingding.facade.special.trasfer.today_info.ReqGetTodayInfo;
import com.dingding.facade.special.trasfer.today_info.ResGetTodayInfo;
import com.dingding.facade.special.trasfer.up_posi.ReqSetUserStatusDTO;
import com.dingding.special.order.calculation.service.ICalculationAmountService;
import com.dingding.special.user.driver.service.IDriverUserService;
import com.dingding.special.user.set.service.ISetUserStatusService;

/**
 * @Description 专车dubbo服务
 * @author fengshuonan
 * @date 2016年11月30日 下午8:20:13
 */
@Component("specialFacade")
public class SpecialFacadeImpl implements ISpecialFacade{
	
	@Resource(name = "driverUserService")
	private IDriverUserService driverUserService;
	
	@Resource(name = "setUserStatusService")
	private ISetUserStatusService setUserStatusService;
	
	@Resource(name = "calculationAmountService")
	private ICalculationAmountService calculationAmountService;

	/**
	 * @Description 获取司机当日信息
	 * @author fengshuonan
	 */
	@Override
	public FacadeResult<ResGetTodayInfo> getDriverTodayInfo(ReqGetTodayInfo request) {
		ResGetTodayInfo driverTodayInfo = this.driverUserService.getDriverTodayInfo(request);
		return FacadeResult.SUCCESS(driverTodayInfo);
	}

	/**
	 * @Description 获取司机当日信息
	 * @author fengshuonan
	 */
	@Override
	public FacadeResult<ResGetTodayInfo> getTaxiDriverTodayInfo(ReqGetTodayInfo request) {
		ResGetTodayInfo driverTodayInfo = this.driverUserService.getTaxiDriverTodayInfo(request);
		return FacadeResult.SUCCESS(driverTodayInfo);
	}
	
	/**
	 * @Description 实时上传位置
	 * @author fengshuonan
	 */
	@Override
	public FacadeResult<Object> uploadPosition(ReqSetUserStatusDTO request) {
		ResponseEntity<Object> setDriverStatus = this.setUserStatusService.setDriverStatus(request);
		if(setDriverStatus.getCode() == HttpStatus.SC_OK){
			return FacadeResult.SUCCESS();
		}else{
			return FacadeResult.ERROR(setDriverStatus.getCode(), setDriverStatus.getErrorMessage());
		}
	}

	/**
	 * @Description 时时计算订单的距离价格
	 * @author fengshuonan
	 */
	@Override
	public FacadeResult<ResCalculationAmountDTO> calcOrderPrice(ReqCalculationAmountDTO request) {
		ResponseEntity<ResCalculationAmountDTO> result = calculationAmountService.calculationAmount(request);
		if(result.getCode() == HttpStatus.SC_OK){
			return FacadeResult.SUCCESS(result.getResponseBody());
		}else{
			return FacadeResult.ERROR(result.getCode(), result.getErrorMessage());
		}
	}
	
	/**
	 * @Description 推送给乘客实时计算距离
	 * @author fengshuonan
	 */
	@Override
	public FacadeResult<Boolean> pushCustomerCalcPrice(String userId,ResCalculationAmountDTO resCalculationAmountDTO){
		calculationAmountService.createPush(userId, resCalculationAmountDTO);
		return FacadeResult.SUCCESS();
	}

}
